<?
// get all assigned fee in a category
if(!empty($fee_by_cat)){
	foreach($fee_by_cat as $fees){
			$ass_fee[$fees->fee_name]['id'] = $fees->fee_id;
			$ass_fee[$fees->fee_name]['rate'] = $fees->fee_rate;
	}
}
// get all available fees 
foreach($get_all_fees as $fees){
	$all_fee[$fees->fee_name]['id'] = $fees->fee_id;
	$all_fee[$fees->fee_name]['rate'] = $fees->fee_rate;
}

// check if fee is already assigned or not
if(!empty($ass_fee)){
	foreach($all_fee as $key => $value){
			if(!array_key_exists($key,$ass_fee)){
				$available_fee[$key] = $value;	
			}
	}
}else{
	$available_fee = $all_fee;
}
?>

<div class="grid_9">

<?php if($this->session->flashdata('type')): ?>
	<div class="<?php echo $this->session->flashdata('type')?>"><?php echo $this->session->flashdata('msg')?></div>
<?php endif; ?>
<div class="inner-border">
<h6>Edit "<?=$category[0]->fee_cat_name;?>" Category</h6>
	<?php 
		$formAttrib = array('id' => 'addfee', 'class' => 'admin-form');
		$catFeeNameAttrib = array('name' => 'fee_cat_name', 'value' => $category[0]->fee_cat_name, 'id' => 'fee_cat_name');
		$catFeeDescAttrib = array('name' => 'fee_cat_desc', 'value' => $category[0]->fee_cat_desc, 'id' => 'fee_cat_desc');
		
		echo form_open('post/edit_fee_category', $formAttrib);
	?>
    
    <div class="input-block">
    <?php
		echo form_label('Category Name:', 'catfeename');
		echo form_input($catFeeNameAttrib);
	?>
    </div>
	<div class="input-block">
    <?php
		echo form_label('Description:', 'catfeedesc');
		echo form_textarea($catFeeDescAttrib);
	?>
    </div>

<table>
<thead>
	<th class="level">Assigned Fees for "<?=$category[0]->fee_cat_name;?>" Category</th><th class="fee_edit"></th><th class="fee_delete"></th>
</thead>

<tbody class="tabular">
		
    	<tr>
			<?if(!empty($ass_fee)):?>
			<tr><th><h5>assigned Fees</h5></th></tr>
				<?foreach ($ass_fee as $key => $value):?>
					<tr><td><li class="no-list"><input type="checkbox" name="fee[]" value="<?=$value['id'];?>" checked/> <?=$key;?></li></td>
						<td><?=$value['rate'];?></td>
					</tr>
					<?$sum_of_assigned[] = $value['rate']?>
				<?endforeach;?>
				<tr><td>total:</td><td><?=array_sum($sum_of_assigned); ?></td></tr>
				<input type="hidden" name="fee_cat_id"value="<?=$category[0]->fee_cat_id;?>">
			<?else:?>
				<td><h5>assigned Fees</h5>
					<div class="notice">Fee is not yet set</div>
				</td>
			<?endif;?>
		</tr>
		<tr>
			
			<?if(!empty($available_fee)):?>
			
				<tr><th><h5>unassigned Fees</h5></th></tr>
				<?foreach ($available_fee as $key => $value):?>
					<tr>
						<td><li class="no-list"><input type="checkbox" name="fee[]" value="<?=$value['id'];?>"/> <?=$key;?></li></td>
						<td><?=$value['rate'];?></td>
					<tr>
					<?$sum_of_unassigned[] = $value['rate']?>
				<?endforeach;?>
				<tr><td>total:</td><td><?=array_sum($sum_of_unassigned);?></td></tr>
				<input type="hidden" name="fee_cat_id"value="<?=$category[0]->fee_cat_id;?>">
			<?else:?>
				<td><h5>unassigned Fees</h5>
					<div class="notice">No Fee available</div>
				</td>
			<?endif;?>
    	</tr>
		
</tbody>
</table>
    <div class="input-block">
    <?php echo form_submit('add', 'Update');
		  echo form_close();
	?>
	<a href="<?php echo site_url('admin/fee_category_creator') ?>" class="btn">Back</a>
    </div>
</div>
</div>